﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Announcement.DAL.DataSetGarageTableAdapters;
using Announcement.DAL.DataSetGarageDetailsTableAdapters;
using Announcement.Model;

namespace Announcement
{
    public partial class Garage : LoginPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ApplyTable at = (ApplyTable)Session["ApplyTable"];
                string cCode = at.ContractCode;
                DateTime applyDate = (DateTime)at.ApplyDate;

                txtFillDate.Text = applyDate.ToString("yyyy-MM-dd");
                hfCCode.Value = cCode;
            }
        }


        protected void btnNext_Click(object sender, EventArgs e)
        {
            //取得表单数据
            GarageTable g = new GarageTable();
            g.HouseSum = Convert.ToInt32(txtHouseSum.Text);
            g.HouseSold = Convert.ToInt32(txtHouseSold.Text);
            g.HouseUnsold = Convert.ToInt32(txtHouseUnsold.Text);
            g.HouseSoldRate = Convert.ToDecimal(txtHouseSoldRate.Text);
            g.HouseIsSell = cbHouseIsSell.Checked;
            g.GarageSum = Convert.ToInt32(txtGarageSum.Text);
            g.GarageSold = Convert.ToInt32(txtGarageSold.Text);
            g.GarageUnsold = Convert.ToInt32(txtGarageUnsold.Text);
            g.GaragePlanSell = Convert.ToInt32(txtGaragePlanSell.Text);
            g.GaragePlanRate = Convert.ToDecimal(txtGaragePlanRate.Text);
            g.DistrictName = txtDistrictName.Text;
            g.DevelopersName = txtDevelopersName.Text;
            g.StartDate = DateTime.Parse(txtStartDate.Text);
            g.EndDate = DateTime.Parse(txtEndDate.Text);
            g.FillDate = DateTime.Parse(txtFillDate.Text);
            Session["GarageTable"] = g;

            Garage_Details gd1 = new Garage_Details();
            gd1.Number = txtNumber1.Text;
            gd1.Area = Convert.ToDecimal(txtArea1.Text);
            gd1.UnitPrice = Convert.ToDecimal(txtUnitPrice1.Text);
            gd1.TotalPrice = Convert.ToDecimal(txtTotalPrice1.Text);
            Session["Garage_Details1"] = gd1;

            if (txtNumber2.Text.Length > 0 || txtArea2.Text.Length > 0
                || txtUnitPrice2.Text.Length > 0 || txtTotalPrice2.Text.Length > 0)
            {
                Garage_Details gd2 = new Garage_Details();
                gd2.Number = txtNumber2.Text;
                gd2.Area = Convert.ToDecimal(txtArea2.Text);
                gd2.UnitPrice = Convert.ToDecimal(txtUnitPrice2.Text);
                gd2.TotalPrice = Convert.ToDecimal(txtTotalPrice2.Text);
                Session["Garage_Details2"] = gd2;
            }

            if (txtNumber3.Text.Length > 0 || txtArea3.Text.Length > 0
                || txtUnitPrice3.Text.Length > 0 || txtTotalPrice3.Text.Length > 0)
            {
                Garage_Details gd3 = new Garage_Details();
                gd3.Number = txtNumber3.Text;
                gd3.Area = Convert.ToDecimal(txtArea3.Text);
                gd3.UnitPrice = Convert.ToDecimal(txtUnitPrice3.Text);
                gd3.TotalPrice = Convert.ToDecimal(txtTotalPrice3.Text);
                Session["Garage_Details3"] = gd3;
            }

            if (txtNumber4.Text.Length > 0 || txtArea4.Text.Length > 0
                || txtUnitPrice4.Text.Length > 0 || txtTotalPrice4.Text.Length > 0)
            {
                Garage_Details gd4 = new Garage_Details();
                gd4.Number = txtNumber4.Text;
                gd4.Area = Convert.ToDecimal(txtArea4.Text);
                gd4.UnitPrice = Convert.ToDecimal(txtUnitPrice4.Text);
                gd4.TotalPrice = Convert.ToDecimal(txtTotalPrice4.Text);
                Session["Garage_Details4"] = gd4;
            }
            Server.Transfer("Sell.aspx");
        }

        protected void lbtnExit_Click(object sender, EventArgs e)
        {
            Session["UserName"] = null;
            Response.Redirect("~/Login.aspx");
        }

    }
}
